package dao

import (
	"WORKSPACE/models"
)

func GetAllorders() (error, []models.Orders, int64) {
	var ordersData []models.Orders
	var total int64
	err := db.Table("orders").Select("order_id","consumer_id","goods_id","order_date","trans_request","is_available","trans_fare").Order("order_id ASC").Find(&ordersData).Error
	return err, ordersData, total
}

func Addorders(order models.Orders) (error) {
	err := db.Table("orders").Select("consumer_id","goods_id","order_date","trans_request").Create(&order).Error
	return err
}

func Updateorders(order models.Orders) (error) {
	err := db.Table("orders").Where("order_id = ?", order.Order_id).Updates(&order).Error
	return err
}

func Delorders(id string) error {
	err := db.Table("orders").Where("order_id = ?", id).Update("is_del",true).Error
	return err
}